package dao;

import hibernateUtils.HibernateUtil;

import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import beans.RubroBean;

public class HibernateRubroDAO {
	private static HibernateRubroDAO instancia;
	private static SessionFactory sf;

	private HibernateRubroDAO() {

	}

	public static HibernateRubroDAO getInstancia() {
		if (instancia == null) {
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateRubroDAO();
		}
		return instancia;
	}

	public void grabarRubro(RubroBean rubro) {
		Session sesion = sf.openSession();
		sesion.beginTransaction();
		sesion.persist(rubro);
		sesion.flush();
		sesion.getTransaction().commit();
		sesion.close();

	}

	public RubroBean buscarRubro(RubroBean rubrob) {
		Session session = sf.openSession();
		rubrob = (RubroBean) session.get(RubroBean.class, rubrob.getIdRubro());
		session.close();
		return rubrob;
	}

	public void update(RubroBean rubro) {
		Session sesion = sf.openSession();
		sesion.beginTransaction();
		sesion.update(rubro);
		sesion.flush();
		sesion.getTransaction().commit();
		sesion.close();

	}
}
